package com.yyy.tcc.service.compensation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
public class HybridCompensationService {
    private static final Logger log = LoggerFactory.getLogger(HybridCompensationService.class);

    private final KafkaCompensationService kafkaService;
    private final ScheduledCompensationService scheduledService;

    @Autowired
    public HybridCompensationService(KafkaCompensationService kafkaService,
                                   ScheduledCompensationService scheduledService) {
        this.kafkaService = kafkaService;
        this.scheduledService = scheduledService;
    }

    /**
     * 关闭服务
     */
    public void shutdown() {
        try {
            kafkaService.shutdown();
        } catch (Exception e) {
            // 记录错误但继续执行
            log.error("关闭Kafka服务失败", e);
        }

        try {
            scheduledService.shutdown();
        } catch (Exception e) {
            log.error("关闭定时任务服务失败", e);
        }
    }
}
